package com.sean.findme.other;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.sean.findme.FmActivityInfo;
import com.sean.findme.FmActivityMgrCtrller;
import com.sean.findme.R;
import com.sean.findme.near.NearActivityManager;

public class OtherActivityGroup extends ActivityGroup{

	LinearLayout container = null;
	OtherActivityManager otherActivityMgr = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.groupactivity);
		
		otherActivityMgr = new OtherActivityManager(this);
		FmActivityMgrCtrller.getInstance(null).setCurActivityMgr(getResources().getString(R.string.other_tab));
		FmActivityMgrCtrller.getInstance(null).registerActivityMgr(getResources().getString(R.string.other_tab), otherActivityMgr );
		
		container = (LinearLayout)findViewById(R.id.group_activity_layout);
		container.removeAllViews();
		
		Intent intent = new Intent( OtherActivityGroup.this, OtherMainActivity.class );
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		
		otherActivityMgr.configFirstActivity(this);
		
		Window subActivity = this.getLocalActivityManager().startActivity("OtherMainActivity", intent);
		View view = subActivity.getDecorView();
		container.addView(view);
		
		LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams();
		params.width = LayoutParams.FILL_PARENT;
		params.height = LayoutParams.FILL_PARENT;
		view.setLayoutParams(params);
		
	}
	
	
	
	@Override
	public void onBackPressed() {
		if( otherActivityMgr.getListActivityInfo().size() <= 1 )
			super.onBackPressed();
		else
		{
			otherActivityMgr.getListActivityInfo().pop().getFromCls();;
			FmActivityInfo info = otherActivityMgr.getListActivityInfo().peek();
			otherActivityMgr.JmpActivity(this.getCurrentActivity().getBaseContext(), info.getFromCls(), info.getActivityGroup(), info.getMap(),false);
		}
	}
	

	
}
